package com.gitee.chenyaohua.oa.domain;

import com.gitee.chenyaohua.oa.anno.FilterField;
import com.gitee.chenyaohua.oa.config.SensitiveData;
import com.gitee.chenyaohua.oa.from.dto.EncryptionType;
import com.gitee.chenyaohua.oa.from.validator.UserModifieCheck;
import lombok.Data;
import org.hibernate.annotations.GenericGenerator;

import javax.persistence.*;
import javax.validation.constraints.Email;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Size;
import java.util.Date;
import java.util.List;


@Data
@Entity
@Table(name = "t_user",indexes = {
		@Index(name = "t_user_name",columnList = "user_name")
})
public class TUser {
	
	@NotBlank(groups = UserModifieCheck.class,message = "用户名id不能是空")
	@Id
	@GeneratedValue(generator = "idGenerator", strategy = GenerationType.SEQUENCE)
	@GenericGenerator(name = "idGenerator", strategy = "com.gitee.chenyaohua.oa.util.hibernate.ext.TimeBaseIdGenerator")    
    private String userId;

	@NotBlank(groups = UserModifieCheck.class,message = "用户名不能是空")
	@Size(groups = UserModifieCheck.class,message = "用户名必须小于20个字符",max = 20)
	@Column(name = "user_name",nullable = false,length = 20)
    private String userName;

	@FilterField(type=EncryptionType.DESEDE)
	@Convert(converter = SensitiveData.class)
	@NotBlank(groups = UserModifieCheck.class,message = "邮箱不能是空")
	@Size(groups = UserModifieCheck.class,message = "邮箱必须小于40个字符",max = 40)
	@Email(groups = UserModifieCheck.class,message = "邮箱不符合规则")
	@Column(name = "user_eamil",unique = true,nullable = false, length = 100)
    private String userEmail;

	@FilterField(type=EncryptionType.MD5)
	@NotBlank(groups = UserModifieCheck.class,message = "密码不能是空")
	@Size(groups = UserModifieCheck.class,message = "密码必须小于20个字符",max = 20,min=6)
	@Column(name = "user_passwrod",nullable = false,length=400)
	private String userPasswrod;
	/**
	 * M 男
	 * F 女
	 */
	@Column(name = "user_sex",length=2)
	private String userSex;

	@Column(name = "create_date",nullable = false,updatable = false)
    private Date createDate;

	@Column(name = "update_date",nullable = false)
    private Date updateDate;
	
	@ManyToMany(fetch = FetchType.LAZY)
	private List<TRole> roles; 

    
}